﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.ServiceModel;

namespace WcfContrib.Client
{
    /// <summary>
    /// Represents an channel invocation context
    /// </summary>
    public class ChannelInvokeContext : IExtensibleObject<ChannelInvokeContext>
    {
        /// <summary>
        /// Gets the type of the contract.
        /// </summary>
        /// <value>The type of the contract.</value>
        public Type ContractType { get; private set; }
        /// <summary>
        /// Gets the type of the client instance.
        /// </summary>
        /// <value>The type of the instance.</value>
        public Type InstanceType { get; private set; }
        /// <summary>
        /// Gets the method.
        /// </summary>
        /// <value>The method.</value>
        public MethodBase Method { get; internal set; }

        /// <summary>
        /// Gets the parameters sent to the method.
        /// </summary>
        /// <value>The parameters.</value>
        public object[] Parameters { get; internal set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChannelInvokeContext"/> class.
        /// </summary>
        /// <param name="instanceType">Type of the client instance.</param>
        /// <param name="contractType">Type of the contract.</param>
        /// <param name="method">The method that was invoked.</param>
        /// <param name="parameters">The parameters sent to the method.</param>
        public ChannelInvokeContext(Type instanceType, Type contractType, MethodBase method, object[] parameters)
        {
            InstanceType = instanceType;
            ContractType = contractType;
            Method = method;
            Parameters = parameters;

            extensions = new ExtensionCollection<ChannelInvokeContext>(this);
        }

        #region IExtensibleObject<ChannelInvokeContext> Members
        ExtensionCollection<ChannelInvokeContext> extensions;
        /// <summary>
        /// Gets a collection of extension objects for this extensible object.
        /// </summary>
        /// <value></value>
        /// <returns>A <see cref="T:System.ServiceModel.IExtensionCollection`1"/> of extension objects.</returns>
        public IExtensionCollection<ChannelInvokeContext> Extensions
        {
            get { return extensions; }
        }
        #endregion
    }
}
